feat: Add full support for nested navigation in MkDocs configuration#37
Open
agpenton wants to merge 4 commits intoWorkable:mainfrom
Open
feat: Add full support for nested navigation in MkDocs configuration#37agpenton wants to merge 4 commits intoWorkable:mainfrom
agpenton wants to merge 4 commits intoWorkable:mainfrom
Conversation
This commit implements complete support for nested navigation structures
in the MkDocs 'nav' section, allowing for arbitrary nesting depth when
publishing to Confluence.
Key Changes:
- Modified traverse() in context.js to track parent-child relationships
- Added parentPath property to LocalPage to store section hierarchy
- Rewrote syncPages() to process pages level-by-level (parents before children)
- Updated README to highlight nesting support and remove limitation notice
- Added comprehensive test fixtures for nested structures
Benefits:
- Pages now maintain their hierarchical structure in Confluence
- First page in each section becomes the parent for that section
- Supports arbitrary nesting depth (e.g., Section > Subsection > Page)
- Fully backward compatible with existing flat structures
Example:
nav:
- Home: index.md # Root level
- Guides: # Section
- Getting Started: guides/start.md # Child of Guides
- Advanced: # Nested section
- Config: guides/adv/config.md # Child of Advanced
All tests pass (148/148) with 99.63% code coverage maintained.
The previous implementation had a critical flaw in how it tracked section
hierarchies. Section headers in MkDocs nav are just labels, not pages.
Changes:
- Added sectionHierarchy tracking to map section names to parent sections
- Modified traverse() to build section hierarchy while parsing nav
- Updated syncPages() to use section hierarchy for proper parent assignment
- The first page in a section now correctly represents that section
- Child sections properly reference their parent section's first page
- Fixed orphan page handling to process even when no local pages exist
Example flow:
nav:
- Guides:
- Start: start.md
- Advanced:
- Config: config.md
Result:
Home (id=100)
- Start (id=101, represents 'Guides')
- Config (id=102, child of 'Start' which represents 'Advanced')
All tests passing (148/148) with proper hierarchy support.
Critical bug: When processing root-level pages (sectionName === null), the first page's ID was overwriting the home page ID in syncedPages map. This caused all subsequent sections to use the wrong parent. Example bug: - First root page 'Solution Draft' (id=101) overwrote home (id=100) - 'Subscriptions' section then used 101 as parent instead of 100 - Result: Subscriptions appeared under Solution Draft instead of Home Fix: Only update syncedPages map for actual sections (sectionName !== null), never for root level which should always remain the home page ID. All tests passing (148/148).
Implemented automatic detection and use of README.md files as section
placeholder pages in Confluence. This provides a much better user
experience than using the first child page to represent a section.
How it works:
1. After parsing nav, detect sections and their children
2. Infer section directory from children's file paths
3. Look for README.md in that directory
4. If found, create a page for it with the section title
5. Use README page as parent for section children
6. Prioritize README pages by sorting them first during sync
Example:
docs/
subscriptions/
README.md ← Becomes "Subscriptions" page
overview.md
development/
README.md ← Becomes "Development" page
arch.md
Result in Confluence:
Home
└─ Subscriptions (from subscriptions/README.md)
├─ Overview
└─ Development (from subscriptions/development/README.md)
└─ Architecture
Benefits:
- Section pages have meaningful content from README.md
- Better matches MkDocs/GitHub documentation patterns
- Falls back to first child if no README.md exists
- Fully backward compatible
All tests passing (148/148).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚀 Feature: Full Support for Nested Navigation in MkDocs
📋 Summary
This PR implements complete support for nested navigation structures in the MkDocs
navsection, allowing documentation to maintain its hierarchical structure when published to Confluence.Closes: Addresses the limitation previously documented in README.md about flattening nested navigation.
🎯 Motivation
Previously, the action flattened all pages to a single level regardless of their nesting in the MkDocs configuration. This meant that hierarchical documentation structures were lost when publishing to Confluence, making it difficult to organize complex documentation.
Before:
After:
✨ What's New
1. Hierarchical Page Structure
Pages now maintain their parent-child relationships as defined in
mkdocs.yml:2. Arbitrary Nesting Depth
Supports unlimited nesting levels - organize your docs however makes sense for your project!
3. Smart Parent Assignment
🔧 Technical Implementation
Core Changes
1. Context Module (
lib/context.js)traverse()function to track parent-child relationships viaparentPathparameter2. LocalPage Model (
lib/models/local-page.js)parentPathproperty to store the section title that contains the page3. Confluence Syncer (
lib/confluence-syncer.js)syncPages()to handle hierarchical structures4. Documentation (
README.md)📊 How It Works
✅ Testing
All Existing Tests Pass
New Test Fixtures
Added comprehensive test fixture for nested structures:
Test Evidence
🔄 Backward Compatibility
✅ Fully backward compatible!
Existing configurations with flat navigation continue to work exactly as before:
All pages are created at root level (under home page) with
parentPath: null.📖 Usage Examples
Simple Nesting
Result in Confluence:
Deep Nesting
Result in Confluence:
🎨 Benefits
📝 Migration Guide
No migration required! This is a pure enhancement.
If you want to start using nested navigation:
mkdocs.ymlto use nested structure🔍 Code Quality
📚 Related Documentation
🙏 Acknowledgments
This implementation follows best practices for:
📋 Checklist